package com.gqj.meter.controller;

import com.gqj.common.annotation.Log;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.core.page.TableDataInfo;
import com.gqj.common.enums.BusinessType;
import com.gqj.common.utils.poi.ExcelUtil;
import com.gqj.meter.domain.SysUpgradeRecord;
import com.gqj.meter.service.ISysUpgradeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 升级记录Controller
 *
 * @author lxq
 * @date lxq-01-09
 */
@RestController
@RequestMapping("/meter/sysUpgradeRecord")
public class SysUpgradeRecordController extends BaseController
{
    @Autowired
    private ISysUpgradeRecordService sysUpgradeRecordService;

    /**
     * 查询升级记录列表
     */
    @PreAuthorize("@ss.hasPermi('meter:sysUpgradeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUpgradeRecord sysUpgradeRecord)
    {
        startPage();
        List<SysUpgradeRecord> list = sysUpgradeRecordService.selectSysUpgradeRecordList(sysUpgradeRecord);
        return getDataTable(list);
    }

    /**
     * 导出升级记录列表
     */
    @PreAuthorize("@ss.hasPermi('storage:sysUpgradeRecord:export')")
    @Log(title = "升级记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUpgradeRecord sysUpgradeRecord)
    {
        List<SysUpgradeRecord> list = sysUpgradeRecordService.selectSysUpgradeRecordList(sysUpgradeRecord);
        ExcelUtil<SysUpgradeRecord> util = new ExcelUtil<SysUpgradeRecord>(SysUpgradeRecord.class);
        util.exportExcel(response, list, "升级记录数据");
    }

    /**
     * 获取升级记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:sysUpgradeRecord:query')")
    @GetMapping(value = "/{upgradeId}")
    public AjaxResult getInfo(@PathVariable("upgradeId") Integer upgradeId)
    {
        return success(sysUpgradeRecordService.selectSysUpgradeRecordByUpgradeId(upgradeId));
    }

    /**
     * 新增升级记录
     */
    @PreAuthorize("@ss.hasPermi('storage:sysUpgradeRecord:add')")
    @Log(title = "升级记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUpgradeRecord sysUpgradeRecord)
    {
        return toAjax(sysUpgradeRecordService.insertSysUpgradeRecord(sysUpgradeRecord));
    }

    /**
     * 修改升级记录
     */
    @PreAuthorize("@ss.hasPermi('storage:sysUpgradeRecord:edit')")
    @Log(title = "升级记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUpgradeRecord sysUpgradeRecord)
    {
        return toAjax(sysUpgradeRecordService.updateSysUpgradeRecord(sysUpgradeRecord));
    }

    /**
     * 删除升级记录
     */
    @PreAuthorize("@ss.hasPermi('storage:sysUpgradeRecord:remove')")
    @Log(title = "升级记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{upgradeIds}")
    public AjaxResult remove(@PathVariable Integer[] upgradeIds)
    {
        return toAjax(sysUpgradeRecordService.deleteSysUpgradeRecordByUpgradeIds(upgradeIds));
    }
}
